package com.protocols.sctp.m3ua;

import com.protocols.GeneralProtocolData;
import com.protocols.OctaveInteger;
import com.protocols.ProtoOperations;
import com.protocols.ProtocolStackException;

public class M3uaASPACAck implements GeneralProtocolData{

	private OctaveInteger M3ua_Version= new OctaveInteger(1,1);
	private OctaveInteger Reserved= new OctaveInteger(0,1);
	private OctaveInteger M3ua_Message_class= new OctaveInteger(4,1);	//ASP Traffic MAintenance Message	
	private OctaveInteger M3ua_Message_type= new OctaveInteger(3, 1);// ASP Active Ack Message
	private OctaveInteger M3ua_MessageLength= new OctaveInteger(4);
	
	public TrafficModeType TrafficModeType = new TrafficModeType(false);
	public RoutingContext RoutingContext = new RoutingContext(false);
	public InfoString InfoString = new InfoString(false);
	public M3uaASPACAck() {
		
	}
	
	public byte [] getByteArray(){		
		
		M3ua_MessageLength.setValue(8+RoutingContext.getLength());
		return  ProtoOperations.concatArrays(M3ua_Version.getByteArray(), Reserved.getByteArray(), M3ua_Message_class.getByteArray(), M3ua_Message_type.getByteArray(), M3ua_MessageLength.getByteArray(), RoutingContext.getByteArray());

		
	}

	public int getLength(){
		return getByteArray().length;
	}
	
	public int getM3ua_Version() {
		return M3ua_Version.Value;
	}


	public int getM3ua_Message_class() {
		return M3ua_Message_class.Value;
	}



	public int getM3ua_Message_type() {
		return M3ua_Message_type.Value;
	}



	public int getM3ua_MessageLength() {
		return M3ua_MessageLength.Value;
	}

	public byte[] decode(byte [] input) throws ProtocolStackException{
		
		if (input[0]==1 && input[2]==4 && input[3]==3){			
			
			M3ua_MessageLength.Value= ProtoOperations.intFromByteArray(input, 4, 4);
			
			// extract the m3ua body
			byte [] remainder = ProtoOperations.extractByteArray(input, 8,M3ua_MessageLength.Value-8 );
			
			remainder = TrafficModeType.decode(remainder);
			InfoString.decode(remainder);		
			
		}
		else
			throw new ProtocolStackException("Decode Failure:M3uaASPACAck"+ProtoOperations.getHexString(input));
		
		return null;
		
	}

	
	
	
	

}
